﻿using System;
using System.Linq;
using System.Windows;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.UnityExtensions;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Prism.MefExtensions;
using System.Collections.Generic;
using Microsoft.Practices.Prism.Regions;
using System.Windows.Controls;
using BizControl.Presentation.Infrastructure.RegionAdapters;

namespace BizControl.Presentation.Shell
{
  class Bootstraper : MefBootstrapper
  {
    protected override DependencyObject CreateShell()
    {
      return this.Container.GetExportedValue<Shell>();
    }

    protected override void InitializeShell()
    {
      base.InitializeShell();

      App.Current.MainWindow = (Shell)this.Shell;
      App.Current.MainWindow.Show();
    }

    protected override RegionAdapterMappings ConfigureRegionAdapterMappings()
    {
      RegionAdapterMappings mappings = base.ConfigureRegionAdapterMappings();
      mappings.RegisterMapping(typeof(StackPanel), this.Container.GetExportedValue<StackPanelAdapter>());
      return mappings;
    }

    protected override void ConfigureAggregateCatalog()
    {
      base.ConfigureAggregateCatalog();

      // Adapters
      this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(StackPanelAdapter).Assembly));

      // Modules
      this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Bootstraper).Assembly));
      this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(ActivitiesModule.ActivitiesModule).Assembly));
      this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(AboutModule.AboutModule).Assembly));
      this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(ActivityEditModule.ActivityEditModule).Assembly));
      this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(StickyNotesModule.StickyNotesModule).Assembly));
      this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(CategoriesModule.CategoriesModule).Assembly));
      this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(PeopleModule.PeopleModule).Assembly));
      this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(PersonEditModule.PersonEditModule).Assembly));
      this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(PersonMarksModule.PersonMarksModule).Assembly));
      this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(PersonMarkEditModule.PersonMarkEditModule).Assembly));
      this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(GraphModule.GraphModule).Assembly));
      this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(BusinessRolesModule.BusinessRolesModule).Assembly));
      this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(DataStatistics.DataStatisticsModule).Assembly));
    }
  }
}
